package com.itheima.goods.controller;


import com.itheima.goods.pojo.Category;
import com.itheima.goods.service.CategoryService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/findAll")
    public Result findAll(){
        return categoryService.findAll();
    }

    @PostMapping("/add")
    public Result add(@RequestBody Category category){
        return categoryService.add(category);
    }

    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
        return categoryService.findPage(page,size);
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return categoryService.findById(id);
    }

    @PutMapping("/{id}")
    public Result update(@RequestBody Category category,@PathVariable("id") Integer id){
        return categoryService.updateId(category,id);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return categoryService.delete(id);
    }

}
